<?php
/*
 * record 控制器
 */
require_once APP_ROOT.'/include/action/commonAction.php';
class Options_Action extends commonAction{

	function index(){
		$page_title ="系统设置";
		extract($this -> options_cache);
		$site_title = $page_title . ' - ' . $site_name;
		include View::getView('options_index');
	}

	function handle(){
		$token = isset($_REQUEST['token']) ? addslashes($_REQUEST['token']) : '';
        if ($token != LoginAuth::genToken()) {
            exit('{"code":108,"msg":"权限不足！"}');
        }

		$action = isset($_POST['action'])?trim($_POST['action']):'';
		$methodName = 'handle_'.$action;
		if(method_exists($this, $methodName)){
			$this -> $methodName();
		}
	}

	function handle_save(){
		$site_name = isset($_POST['site_name'])?addslashes(trim($_POST['site_name'])):'';
		$site_keyword = isset($_POST['site_keyword'])?addslashes(trim($_POST['site_keyword'])):'';
		$site_content = isset($_POST['site_content'])?addslashes(trim($_POST['site_content'])):'';
		$site_url = isset($_POST['site_url'])?addslashes(trim($_POST['site_url'])):'';
		$safecode = isset($_POST['safecode'])?addslashes(trim($_POST['safecode'])):'';

		$optionsData = array(
			'site_name' => $site_name,
			'site_keyword' => $site_keyword,
			'site_content' => $site_content,
			'site_url' => $site_url,
			'safecode' => $safecode,
		);

		foreach($optionsData as $key => $option):
			Option::updateOption($key, $option);
		endforeach;

		$this -> CACHE -> updateCache('options');
		exit('{"result":200,"msg":"更新成功！"}');
	}

}